package com.bwei.like.mynewstop.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
<<<<<<< 77331352d74e6afdfbbeaccca4370d33ffbea935
=======
import android.view.KeyEvent;
import android.view.MotionEvent;
>>>>>>> NewsTop
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
<<<<<<< 77331352d74e6afdfbbeaccca4370d33ffbea935
=======
import android.widget.ProgressBar;
>>>>>>> NewsTop

import com.bwei.like.mynewstop.Bean.NewsCategoryRoot;
import com.bwei.like.mynewstop.R;

import java.io.Serializable;

<<<<<<< 77331352d74e6afdfbbeaccca4370d33ffbea935
public class WebView_activity extends AppCompatActivity {

    private WebView webView;
    private NewsCategoryRoot.DataBean dataBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
=======
public class WebView_activity extends BaseActivity implements View.OnTouchListener {

    private WebView webView;
    private NewsCategoryRoot.DataBean dataBean;
    private float xDown;
    private ProgressBar progressBar;

    @Override
    public void onCreate(Bundle savedInstanceState) {
>>>>>>> NewsTop
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        initView();
        webView.loadUrl(dataBean.getUrl());
<<<<<<< 77331352d74e6afdfbbeaccca4370d33ffbea935
=======
        webView.setWebViewClient(new WebViewClient() {

        });
        webView.setOnTouchListener(this);
>>>>>>> NewsTop
    }

    private void initView() {
        webView = (WebView) findViewById(R.id.webView);
<<<<<<< 77331352d74e6afdfbbeaccca4370d33ffbea935
        dataBean = (NewsCategoryRoot.DataBean) getIntent().getSerializableExtra("DataBean");
        WebSettings settings = webView.getSettings();
        webView.setWebViewClient(new WebViewClient());

    }
}
=======
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        dataBean = (NewsCategoryRoot.DataBean) getIntent().getSerializableExtra("DataBean");
        WebSettings settings = webView.getSettings();
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        WebSettings webSettings = webView.getSettings();
        //针对设置进度的监听
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(newProgress);
                if (newProgress == 100) {
                    progressBar.setVisibility(View.GONE);
                }
            }
        });

        //设置
        initSettings();
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                xDown = event.getX();
                break;
            case MotionEvent.ACTION_UP:
                float xUp = event.getX();
                if (xUp - 100 > xDown) {
                    finish();
//                    overridePendingTransition(R.anim.);
                }
                break;
        }
        return true;
    }

    private void initSettings() {
        WebSettings settings = webView.getSettings();
        //是否自动打开窗口
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        //是否识别jsp
        settings.setJavaScriptEnabled(true);
        //设置如何缓存
        settings.setCacheMode(WebSettings.LOAD_DEFAULT);
        //是否展示缩放按钮
        settings.setBuiltInZoomControls(true);
        //设置默认的缩放比例
        settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (webView.canGoBack()) {
                webView.goBack();
            } else {
                finish();
            }
        }

        return true;

    }


}
>>>>>>> NewsTop
